import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {
    //这里通过返回值向上转型了
    public static User login() {
        System.out.print("请输入你的姓名：");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();
        System.out.println("1 - 管理员");
        System.out.println("0 - 普通用户");
        System.out.print("请输入你的身份->");
        if (in.nextInt() == 1) {
            return new AdminUser(name);
        } else {
            return new NormalUser(name);
        }
    }

    public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        while (true) {
            int choice = user.menu();
            //根据 menu() 返回的 choice 和 login() 返回的 user 来确定调用哪个对象的哪个操作？
            user.doWork(choice, bookList);
        }
    }
}
